//
//  TableViewCell.m
//  TableView
//
//  Created by Carl_fang on 15/3/26.
//  Copyright (c) 2015年 Carl_fang. All rights reserved.
//

#import "TableViewCell.h"
#import "HotMovieModel.h"
#import "UIImageView+WebCache.h"


@interface TableViewCell()

@property (nonatomic, retain) UIImageView *picImage;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *titleCn;
@property (nonatomic, retain) UILabel *ratingFinalLabel;
@property (nonatomic, retain) UILabel *rDate;
//场次
@property (nonatomic, retain) UILabel *times;


@end


@implementation TableViewCell


- (void)setModel:(HotMovieModel *)model
{
//    _model = model;
//    NSURL *url = [[NSURL alloc] initWithString:model.img];
//    NSData *data = [NSData dataWithContentsOfURL:url];
//    UIImage *image = [UIImage imageWithData:data];
//    self.picImage.image = image;
    //self.picImage.backgroundColor = [UIColor redColor];
    self.titleCn.text = model.titleCn;
    //出了BUG
//    if (model.ratingFinal == nil) {
//        self.ratingFinalLabel.text = @"---";
//    }else
//    {
//    self.ratingFinalLabel.text = model.ratingFinal;
//    }
//    if ([model.ratingFinal isEqualToString:@"8.199999999999999"]) {
//        self.ratingFinalLabel.text = @"8.1";
//    } else
//    {
//        self.ratingFinalLabel.text = model.ratingFinal;
//    }
//    
    
//    NSLog(@"%@",model.ratingFinal);
    NSString *date = [NSString stringWithFormat:@"%@月%@日上映",model.rMonth,model.rDay];
    self.rDate.text = date;
    NSString *str = [NSString stringWithFormat:@"“ %@",model.commonSpecial];
    self.titleLabel.text = str;
    self.movieId = model.movieId;
    
    NSURL *url = [NSURL URLWithString:model.img];
    [self.picImage setImageWithURL:url];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat leftPadding = 10;
        CGFloat topPadding = 10;
        CGFloat picImageW = 60;
        CGFloat picImageH = 80;
        _picImage = [[UIImageView alloc] initWithFrame:CGRectMake(leftPadding, topPadding, picImageW, picImageH)];
        [self.contentView addSubview:_picImage];
        
        CGFloat titleTop = 10;
        CGFloat titleW = 100;
        CGFloat titleH = 15;
        CGFloat titleX = 75;
        _titleCn = [[UILabel alloc] initWithFrame:CGRectMake(titleX, titleTop, titleW, titleH)];
        _titleCn.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_titleCn];
        
        
        
        CGFloat ratingX = 180;
        CGFloat ratingW = 40;
        CGFloat ratingH = 20;
        _ratingFinalLabel = [[UILabel alloc] initWithFrame:CGRectMake(ratingX, 7, ratingW, ratingH)];
        _ratingFinalLabel.textColor = [UIColor greenColor];
//        _ratingFinalLabel.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_ratingFinalLabel];
        
        
        CGFloat titleLabelW = 200;
        CGFloat titleLabelY = 35;
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleX, titleLabelY, titleLabelW, titleH)];
        _titleLabel.font = [UIFont systemFontOfSize:12];
        _titleLabel.textColor = [UIColor orangeColor];
        [self.contentView addSubview:_titleLabel];
        
        
        _rDate = [[UILabel alloc] initWithFrame:CGRectMake(75, 50, titleLabelW, ratingH)];
        _rDate.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_rDate];
        
        
        CGFloat i3DW = 30;
        CGFloat i3DH = 20;
        _i3D = [UIButton buttonWithType:UIButtonTypeSystem];
        //_i3D.backgroundColor = [UIColor yellowColor];
        [_i3D setTitle:@"3D" forState:UIControlStateNormal];
        _i3D.frame = CGRectMake(75, 65, i3DW, i3DH);
        [self.contentView addSubview:_i3D];
        
        
        CGFloat iMaxW = 50;
        _iMAX = [UIButton buttonWithType:UIButtonTypeSystem];
        _iMAX.frame = CGRectMake(110, 65, iMaxW, i3DH);
        [_iMAX setTitle:@"IMAX" forState:UIControlStateNormal];
        _iMAX.titleLabel.font = [UIFont systemFontOfSize:12];
        //_iMAX.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_iMAX];
        
        _largeScreen = [UIButton buttonWithType:UIButtonTypeSystem];
        _largeScreen.frame = CGRectMake(160, 65, iMaxW, i3DH);
        _largeScreen.titleLabel.font = [UIFont systemFontOfSize:12];
        [_largeScreen setTitle:@"中国巨幕" forState:UIControlStateNormal];
        //_largeScreen.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_largeScreen];
        
        
//        _buy = [UIButton buttonWithType:UIButtonTypeSystem];
//        _buy.frame = CGRectMake(250, 40, 60, 30);
//        [_buy setTitle:@"即将上映" forState:UIControlStateNormal];
//        _buy.layer.borderWidth = 3;
//        _buy.layer.cornerRadius = 5;
//        _buy.layer.borderColor = [UIColor blueColor].CGColor;
//        _buy.backgroundColor = [UIColor orangeColor];
//        [self addSubview:_buy];

    }
    return self;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
